class AddIndexSubPostsToHotPosts < ActiveRecord::Migration
  def self.up
    add_column :hot_posts, :the_first_sub_hot_post_id, :integer
    add_column :hot_posts, :the_last_sub_hot_post_id, :integer
    add_column :hot_posts, :the_first_lz_sub_hot_post_id, :integer
    add_column :hot_posts, :the_last_lz_sub_hot_post_id, :integer
    HotPost.all.each do |hot_post|
      hot_post.the_first_sub_hot_post = hot_post.find_the_first_sub_hot_post
      hot_post.the_last_sub_hot_post = hot_post.find_the_last_sub_hot_post
      hot_post.the_first_lz_sub_hot_post = hot_post.find_the_first_lz_sub_hot_post
      hot_post.the_last_lz_sub_hot_post = hot_post.find_the_last_lz_sub_hot_post
      hot_post.save(false)
    end if not Rails.env.test?
  end

  def self.down
    remove_columns :hot_posts,
      :the_first_sub_hot_post_id,
      :the_last_sub_hot_post_id,
      :the_first_lz_sub_hot_post_id,
      :the_last_lz_sub_hot_post_id
  end
end
